package com.thirteen.app.controller;

import com.thirteen.app.entity.College;
import com.thirteen.app.service.CollegeService;
import com.thirteen.app.utils.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 学院(Examcollege)表控制层
 *
 * @author makejava
 * @since 2021-09-03 09:46:06
 */
@CrossOrigin
@Api(tags = "学院管理")
@RestController
@RequestMapping("/api/admin/education/academy")
public class CollegeController {
    /**
     * 服务对象
     */
    @Resource
    private CollegeService collegeService;

    /**
     * 通过主键查询单条数据
     *
     * @param examCollege 学院实体类
     * @return 单条数据
     */
    @ApiOperation("查询学院信息")
    @GetMapping("/select")
    public CommonResult selectCollege(College examCollege) {
        return CommonResult.success(collegeService.queryById(examCollege.getCollegeId()));
    }

    @ApiOperation("全查学院信息")
    @GetMapping("/list")
    public CommonResult listCollege() {
        return CommonResult.success(this.collegeService.queryAll());
    }


    @ApiOperation("添加学院")
    @PostMapping("/save")
    public CommonResult saveCollege(@RequestBody College college) {
        return CommonResult.success(collegeService.insert(college));
    }

    @ApiOperation("分页全查")
    @GetMapping("/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "分页起始值", required = true, defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示多少条记录", required = true, defaultValue = "10", dataType = "Integer")})
    public CommonResult findCollegePage(Integer pageIndex, Integer pageSize) {
        return CommonResult.success(collegeService.queryAllByLimit(pageIndex, pageSize));

    }

    @ApiOperation("删除学院")
    @PostMapping("/delete")
    public CommonResult deleteCollege(@RequestBody College college) {
        return CommonResult.success(collegeService.deleteById(college.getCollegeId()));
    }

    @ApiOperation("更新学院")
    @PostMapping("/edit")
    public CommonResult updateCollege(@RequestBody College college) {
        return CommonResult.success(collegeService.update(college));
    }

}
